/*
'**************************************************
'Function		去空格

'Author			Peace
'Create	Date	2004-09-09
'Parameter		Str				需要去空格的字符串
'**************************************************
*/
function KillSpace(Str,list){
		if(typeof(list) == 'undefined')
			list = ' ';
			
		while((Str.length>0) && list.indexOf(Str.charAt(0))!=-1 )
			 Str = Str.substring(1,Str.length);
		while((Str.length>0) && list.indexOf(Str.charAt(Str.length-1))!=-1)
		     Str = Str.substring(0,Str.length-1);
		
        return Str;
}
function GetCookie(Name) 
{
     var search = Name + "=";
     var returnvalue = "";
     if (document.cookie.length > 0) {
           offset = document.cookie.indexOf(search);
           if (offset != -1) {      
                 offset += search.length;
                 end = document.cookie.indexOf(";", offset);                        
                 if (end == -1)
                       end = document.cookie.length;
                 returnvalue=unescape(document.cookie.substring(offset,end));
           }
     }
     return returnvalue;
}

function GETOBJ(obj)
{
	var element = null;
	if(document.getElementById)
	{
		element = document.getElementById(obj);
	}
	else if(document.all)
	{
		element = document.all[obj];
	}
	else if(document.layers)
	{
		element = document.layers[obj];
	} 
	return element;

} 

function SetCookie(name,value)
{
     var argv=SetCookie.arguments;
     var argc=SetCookie.arguments.length;
     var expires=(2<argc)?argv[2]:null;
     var path=(3<argc)?argv[3]:null;
     var domain=(4<argc)?argv[4]:null;
     var secure=(5<argc)?argv[5]:false;
     document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
function XHConn()
{
	var xmlhttp, bComplete = false;
	try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlHttp = new XMLHttpRequest();  }
	catch (e) { xmlHttp = false; }}}
	if (!xmlHttp) return null;
	
	this.connect = function(sURL, sMethod, sVars, fnDone)
	{
		var retval	= "";
		if (!xmlHttp) return false;
		
		bComplete = false;
		sMethod = sMethod.toUpperCase();
		try {
			xmlHttp.onreadystatechange = fnDone;
			if (sMethod == "GET")
			{
				xmlHttp.open(sMethod, sURL+"?"+sVars, true);
			}
			else
			{
				xmlHttp.open(sMethod, sURL, true);
				xmlHttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			xmlHttp.send(sVars);
		}
		catch(z) {
			alert('需要访问的资源不存在');	
			return false; 
		}
		
	};
	return "";
	
}
var xmlHttp = null;
/*
'**************************************************
'Function		判断FORM TEXT输入是否正确
'Author			Peace
'Create	Date	2004-09-09
'Parameter		Obj				Form object
'				TypeValue		检测类型

'				Msg				提示信息
'**************************************************
*/
function CheckTextB(Obj,TypeValue,Msg)
{
	//TypeValue 2数字类型  8 字符型  100汉字
	//Obj 判断对象
	//Msg 返回内容

	var IsOk=false;
	switch (TypeValue)
	{
		case 2:
			res=/\d{1,}/
			Obj.value=KillSpace(Obj.value);
			if (res.exec(Obj.value))
				IsOk=true;
			else
				IsOk=false;
			if (!IsOk && (Msg.length>0 || Obj.value.length>0))
				{
					if (Obj.style.display == '')
					{
						alert(Msg);
						Obj.focus();
						Obj.select();
					}
					return false;
				}
			else
				return true;
			break;
		case 8:
			Obj.value=KillSpace(Obj.value);
			if (Obj.value.length==0)
				IsOk=true;
			else
				IsOk=false;
			if (IsOk && Msg.length>0)
				{
					alert(Msg);
					if (Obj.style.display == '')
					{
						Obj.focus();
						Obj.select();
					}
					return false;
				}
			else
				return true;
			break;
		case 100:
			Obj.value=KillSpace(Obj.value);
			if (Obj.value.length==0 || !GB_All(Obj.value) )
				IsOk=true;
			else
				IsOk=false;
			if (IsOk && Msg.length>0)
				{
					alert(Msg);
					alert(Obj.style.display);
					if (Obj.style.display == '')
					{
						Obj.focus();
						Obj.select();
					}
					return false;
				}
			else
				return true;
			break;
	
	}
}
/*
'**************************************************
'Function		判断FORM TEXT输入是否正确
'Author			Peace
'Create	Date	2004-09-09
'Parameter		Obj				Form object
'				TypeValue		检测类型

'				Msg				提示信息
'				Necessary		是否是必添字段

'**************************************************
*/
function CheckText(Obj,TypeValue,Msg,Necessary)
{
    /*TypeValue 
    'd': Numeric; 
    'i': All Integer 
    'r': Aeal Number
    'f': Decimal Fraction
    'l': 26 letter
    'ul':[A-Z]
    'll':[a-z]
    'w': [a-zA-Z_0-9]
    'S': Chinese Characters and Special Characters
    'e':email
	'date':
    
    Obj Required. 
    Msg Return Prompt Message
    Necessary is Optional Parameter
    */
    
    if (isNaN(Necessary))
        Necessary=false;
    Obj.value=KillSpace(Obj.value);
    switch (TypeValue)
    {
        case "d":
            res=new RegExp("^[0-9]+$","g");
            break;
        case "i":
            //res=new RegExp("(^[1-9][0-9]*$)|(^[\+\-][1-9][0-9]*$)","g");
			res=new RegExp("^[\+\-]?[0-9]+$","g");
            break
        case "r":
            //res=new RegExp("(^([\+\-]?[1-9])[0-9]*(\.[0-9]+)?[0-9]$)|(^([\+\-]?[0-9]\.)[0-9]+$)","g")
			res=new RegExp("^[\+\-]?[0-9]+(\.)?[0-9]?$","g")
            break;
        case "f":
            //res=new RegExp("(^(0\.)[0-9]+$)|(^[\+\-]0\.[0-9]+$)","g");
			res=new RegExp("^[\+\-]?0\.[0-9]+$","g");
            break;
        case "l":
            res=new RegExp("^[a-z]+$","gi");
            break;
        case "ul":
            res=new RegExp("^[A-Z]+$","g");
            break;
        case "ll":
            res=new RegExp("^[a-z]+$","g");
            break;
        case "w":
            res=new RegExp("^[0-9a-zA-Z_]+$","g")
            break;
        case "S":
            res=new RegExp("[^a-zA-Z0-9\n\r\t\f\v~`!@#$%^&*()\_\+\\/\.,<>\? ]+$","g");
            break;
        case "e":
			res=new RegExp("([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+","g");
			break
		case "date":
			res=new RegExp("^[0-9]{4}\-(0?[1-9]|[1-2][0-2])\-(0?[1-9]|[1-2][0-9]|3[01])$","g");
			break;
		case "datetime":
			res=new RegExp("^[0-9]{4}\-(0?[1-9]|[1-2][0-2])\-(0?[1-9]|[1-2][0-9]|3[01]) [0-9]{2}(:[0-9]{2})+","g");
			break;
		case "ip":
			res=new RegExp("^([1-9]|[1-9][0-9]|[12][0-5][0-9])(\.([0-9]|[1-9][0-9]|[12][0-5][0-9])){3}$","g");
			break;
		case "money":
			res=new RegExp("^[0-9]+(\.[0-9]{2})?$","g");
			break;
		case "":
            res=new RegExp(".+","g");
			break;
		default:
			res=new RegExp(TypeValue,"g");
    }
    //Main Process
    IsOk=res.exec(Obj.value);
    if ((Necessary && !IsOk)||(!IsOk && Obj.value.length > 0 ))
        {
            alert(Msg);
			if (Obj.style.display == '')
			{
				Obj.focus();
				Obj.select();
			}
            return false;
        }
    else
        return true;

}
/**
* 全选操作
*/
function selectAll(obj)
{

	try
	{
		var frm = obj.form;
		var checked = obj.checked;
		for(i=0;i<frm.length;i++)
		{
			if (frm[i].tagName== "INPUT")
			{
				if (frm[i].type=="checkbox")
					frm[i].checked = checked;
			}
		}
	}	
	catch(e)
	{
		alert(e.description);
	}
}
String.prototype.UrlEncode = function()
{
	var str = this;
	str = str.replace(/./g,function(sHex)
	{
		window.EnCodeStr = "";
		window.sHex = sHex;
		window.execScript('window.EnCodeStr=Hex(Asc(window.sHex))',"vbscript");
		return window.EnCodeStr.replace(/../g,"%$&");
	});
	return str;
}
function redirect(url)
{
	if(url.lastIndexOf('/.') > 0) url = url.replace(/\/(\.[a-zA-Z]+)([0-9]+)$/g, "/$2$1");
	if(url.indexOf('://') == -1 && url.substr(0, 1) != '/' && url.substr(0, 1) != '?') url = $('base').attr('href')+url;
	location.href = url;
}
/**
* 当点击搜索的时候，组合搜索的条件
* Create Date			2009-03-12
* Author				peace@warmy.cn
*/
function BeginSearch()
{
	try
	{	
		var str = document.frmList.action;
		var len = document.frmList.length;
		for(i=0;i<len;i++)
		{
			var s = false;
			try
			{
				if(document.frmList[i].getAttribute("IsSearch") == "1")
					s = true;


			}
			catch(e)
			{
				alert(e.description);
			}
			if(s)
			{
				if(str.indexOf(document.frmList[i].name + "=")>=0)
				{
					re = new RegExp("(&?)" + document.frmList[i].name + "=(.[^&]*)*");
					str = str.replace(re,"");
				}
				str += "&" + document.frmList[i].name + "=" + encodeURI(document.frmList[i].value);
			}
		}
		//alert(str);return;
		document.location.href=str;

	}
	catch(e)
	{
		alert(e.description);
	}
}
/**
* 初始化菜单
*/
function Initialize_Menu()
{
	try
	{
		var menuobj = document.getElementById('menu');
		var tr = menuobj.rows;
		var len = tr.length;
		var idx = GetCookie('menu_idx');
		for(i=0;i<len;i++)
		{
			if(idx == i)
			{
				window.current_menu = tr[i+1];
				window.current_menu.className = 'menuBox';
			}
			if(tr[i].className == '' && tr[i+1].className=='menuBoxH')
			{
				(function() {
				var o = tr[i+1];
				var idx = i;
				tr[i].onclick = function()
				{
					if(window.current_menu)
						window.current_menu.className = 'menuBoxH';
					window.current_menu = o;
					window.current_menu.className = 'menuBox';
					SetCookie('menu_idx',idx);
				}
				})();
			}
		}
	}
	catch(e)
	{
		//alert(e.description);
	}
}

